package com.alogic.swagger.core;

import com.alogic.xscript.AbstractLogiclet;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * Contact
 *
 * @since 1.6.13.7 [20200812 duanyy] <br>
 */
public class SwaggerContact extends AbstractLogiclet {
    protected String $name;
    protected String $url;
    protected String $email;

    public SwaggerContact(String tag, Logiclet p) {
        super(tag, p);
    }

    @Override
    public void configure(Properties p){
        super.configure(p);

        $name = PropertiesConstants.getRaw(p,"name","");
        $url = PropertiesConstants.getRaw(p,"url","");
        $email = PropertiesConstants.getRaw(p,"email","");
    }

    @Override
    protected void onExecute(XsObject root, XsObject current, final LogicletContext ctx, final ExecuteWatcher watcher){
        XsObject newCurrent = current.getObjectChild("contact",true);
        newCurrent.addProperty("url",PropertiesConstants.transform(ctx,$url,""));
        newCurrent.addProperty("name",PropertiesConstants.transform(ctx,$name,""));
        newCurrent.addProperty("email",PropertiesConstants.transform(ctx,$email,""));
    }
}